package com.cgtong.android.mvp.model;

import com.cgtong.android.bean.ProblemBean;
import com.cgtong.android.http.ApiManager;
import com.cgtong.android.http.ConstantManager;
import com.cgtong.android.http.callback.ProblemPageCallBack;
import com.cgtong.android.mvp.contract.HisProblemsContract;
import com.zhouyou.http.EasyHttp;
import com.zhouyou.http.callback.CallBackProxy;
import com.zhouyou.http.callback.SimpleCallBack;
import com.zhouyou.http.exception.ApiException;
import com.zhouyou.http.model.ApiResult;

import java.util.List;

/**
 * Created by chunc on 2017/10/27.
 */

public class HisProblemsModel implements HisProblemsContract.Model {
    @Override
    public void httpProblemsData(long maxId, long userId, final ProblemPageCallBack<List<ProblemBean>> problemPageCallBack) {
        EasyHttp.post(ApiManager.MINE_PROBLEMPAGE_BY_USERID_URL)
                .params("maxId", String.valueOf(maxId))//支持添加多个参数同时添加
                .params("pageSize", ConstantManager.USER_FOLLOWED_PAGE_SIZE)//支持添加多个参数同时添加
                .params("userId", String.valueOf(userId))//支持添加多个参数同时添加
                .accessToken(true)
                .execute(new CallBackProxy<ApiResult<List<ProblemBean>>, List<ProblemBean>>(new SimpleCallBack<List<ProblemBean>>() {
                    @Override
                    public void onError(ApiException e) {
                        problemPageCallBack.onError(e);
                    }

                    @Override
                    public void onSuccess(List<ProblemBean> problemBeen) {
                        problemPageCallBack.onHttpProblemsSuccess(problemBeen);
                    }
                }) {
                });
    }
}
